package errorWrap

import (
	"errors"
	"fmt"
	e1 "github.com/pkg/errors"
	"strconv"
)

type ErrT struct {
	ss string
	c  int
}

func (m ErrT) Error() string {
	return m.ss + " my :" + strconv.Itoa(m.c)
}

func NewErrT(s string, c int) error {
	return ErrT{s, c}
}

func Et1() {
	listErr := []error{}
	err1 := errors.New("test")
	err2 := NewErrT("t", 1)

	ew1 := e1.Wrap(err1, "read failed")
	ew2 := e1.Wrap(err2, "myErr")
	listErr = append(listErr, ew1)
	listErr = append(listErr, ew2)

	for _, v := range listErr {
		switch e := e1.Cause(v).(type) {
		case *ErrT:
			fmt.Println("嘿嘿我进来了。")
			fmt.Println(e)
			// handle specifically
		default: // unknown error}
			fmt.Println("---")
			fmt.Println(e)
		}
	}

}
